﻿using Blm.Utils.Extensions;
using System.Collections.Generic;
using System.Linq;

namespace VisionCloud.Utility.Security
{
    /// <summary>
    /// 应用代码与Api密码信息
    /// </summary>
    public static class ApiKeyInfo
    {
        public enum ApiKeyEnum
        { Frame = 0, UpperComputer = 1 }

        public class ApiKeyDto
        {
            /// <summary>
            /// 调用方代号
            /// </summary>
            public string ApiKey { get; set; }

            /// <summary>
            /// 调用方的Api密码
            /// </summary>
            public string ApiSecret { get; set; }
        }

        /// <summary>
        /// 应用代码与Api密码信息
        /// </summary>
        public static List<ApiKeyDto> ApiKeyDtos { get; private set; } = ConfigHelper.GetValue<string>("ApiKeyInfo").ToObject<List<ApiKeyDto>>();

        /// <summary>
        /// 获取系统对应的秘钥
        /// </summary>
        /// <param name="apiKey"></param>
        /// <returns></returns>
        public static string GetApiSecret(string apiKey)
        {
            return ApiKeyDtos.Where(p => p.ApiKey == apiKey).FirstOrDefault()?.ApiSecret;
        }
    }
}